package com.cola.service;

import com.cola.bean.User;
import com.cola.utils.BussinessException;
import com.cola.utils.EmptyUtils;
import com.cola.utils.UserIO;

import java.time.chrono.IsoChronology;

/**
 * @Grup:com.cola.service
 * @Auther:cola
 * @Data:2021/4/16-2021-04-18:42
 * @version:1.0
 */
public class UserServiceImpl implements UserServers{
    @Override
    public User register(User user) throws BussinessException {
        UserIO userIO = new UserIO();
        userIO.add(user);
        userIO.writeUser();
        return user;
    }

    @Override
    public User login(String username, String password) throws BussinessException {
        if (EmptyUtils.isEmpty(username)){
            throw new BussinessException("username.notnull");
        }
        if (EmptyUtils.isEmpty(password)){
            throw new BussinessException("password.notnull");
        }
        UserIO userIO = new UserIO();
        User user = userIO.findByUsernameAndpassword(username, password);
        return user;
    }


}
